<template>
  <a-layout id="components-layout-demo-side" style="min-height: 100vh">
    <a-layout-sider v-model="collapsed" collapsible>
      <div v-if="isExpand" class="logo"><img src="@/assets/LOGO02.png" style="margin-right: 10px;" alt="">夏之家院</div>
      <div v-else class="logo"><img src="@/assets/LOGO02.png" alt=""></div>

        <a-menu theme="dark" mode="inline" :default-selected-keys="routerName" :selected-keys="routerName">
          <a-menu-item :key="item.path" v-for="item in routers">
            <router-link :to="item.path" active-class="active">
              <a-icon :type="item.meta && item.meta.iconType" />
              <span>{{ item && item.meta && item.meta.name }}</span>
            </router-link>
          </a-menu-item>
        </a-menu>

    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <!-- <a-icon
          class="trigger"
          :type="collapsed ? 'menu-unfold' : 'menu-fold'"
          @click="() => (collapsed = !collapsed)"
        /> -->
        <div class="subnav">
          <div style="margin-right: 20px;">
            <a-switch default-checked @change="onChange"/>
          </div>
          <a-tooltip style="margin-right: 20px;">
            <template slot="title">
              <div v-for="item in language" :key="item.id" class="user-login">{{ item.name }}</div>
            </template>
            <a href="#">中文</a>
          </a-tooltip>

          <div v-if="isLogin" class="user-name">
            <a-tooltip>
              <template slot="title">
                <div class="user-login" @click="showUserInfo">个人信息</div>
                <div class="user-login" @click="logout">退出登录</div>
              </template>
              <a href="#">{{ userInfo && userInfo.name }}<a-icon style="margin-left: 5px; font-size: 16px;" type="down" /></a>
            </a-tooltip>
          </div>
          <div v-else class="not-login"><a href="#">未登录</a></div>
        </div>
      </a-layout-header>
      <a-layout-content style="margin: 0 16px">
        <a-breadcrumb style="margin: 16px 0">
          <!-- <a-breadcrumb-item>User</a-breadcrumb-item>
          <a-breadcrumb-item>Bill</a-breadcrumb-item> -->
        </a-breadcrumb>
        <div :style="{ padding: '24px', background: '#fff', minHeight: '360px' }">
          <router-view/>
        </div>
      </a-layout-content>
      <a-layout-footer style="text-align: center">
        Ant Design ©2018 Created by Ant UED
      </a-layout-footer>
    </a-layout>
  </a-layout>
</template>
<script>
import route from '@/router'
import { mapMutations, mapState } from 'vuex'

export default {
  watch: {
    collapsed (val) {
      this.SET_EXPAND(val)
    }
  },
  computed: {
    ...mapState({
      isExpand: (state) => state.user.isExpand,
      isLogin: (state) => state.user.isLogin,
      userInfo: (state) => state.user.userInfo,
      routerName: (state) => state.user.router
    })
  },
  data () {
    return {
      collapsed: false,
      routers: route.options.routes[0].children,
      language: [
        { id: 1, name: '中文'},
        { id: 2, name: '英文'},
      ],
      selectLanguage: 1
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    ...mapMutations(['SET_EXPAND']),
    init () {
      this.routers = route.options.routes[0].children.filter(item => item.isShow)
    },
    goUrl () {
      this.$router.push('/')
    },
    logout () {
      localStorage.removeItem('token')
      this.$router.push('/login')
    },
    showUserInfo () {
      this.$router.push('/userInfo')
    },
    onChange(checked) {
      console.log(`a-switch to ${checked}`);
    },
  }
}
</script>

<style lang="less" scoped>
#components-layout-demo-side .logo {
  height: 32px;
  /* background: rgba(255, 255, 255, 0.2); */
  margin: 16px;
  color: white;
  line-height: 32px;
  img {
    margin-bottom: 2px;
  }
}

#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

.subnav{
  float: right;
  margin-right: 60px;
  font-size: 20px;
  font-weight: 700;
  display: flex;
}
.user-login{
  margin: 5px;
  cursor: pointer;
}
.user-login:hover{
  color: rgb(82, 248, 145);
}
.ant-breadcrumb{
  text-align: left;
}
.ant-menu-item{
  text-align: left;
}
</style>
